<?php
namespace App\Repositories\Teambition;

use App\Models\Teambition;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\Paginator;

class TeambitionDBRepository implements TeambitionRepository
{
    /**
     * @param TeambitionFilter $userFilter
     * @return Paginator
     */
    public function getPaginator(TeambitionFilter $teambitionFilter)
    {
        $query = $this->getDBQuery($teambitionFilter);

        return $query->paginate($teambitionFilter->getPerPage());
    }

    protected function getDBQuery(TeambitionFilter $teambitionFilter)
    {
        /** @var Builder $billQuery */
        $teambitionQuery = Teambition::query();

        if ($name = $teambitionFilter->getName()){
            $teambitionQuery->where('name', $name);
        }

        if ($teambitionSign = $teambitionFilter->getTeambitionSign()){
            $teambitionQuery->where('teambition_sign', $teambitionSign);
        }
        return $teambitionQuery;

    }
}
